package cn.tannn.ops.util;/*
 * acme4j - Java ACME client
 *
 * Copyright (C) 2015 Richard "Shred" Körber
 *   http://acme4j.shredzone.org
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 */

import cn.tannn.ops.common.constant.CloudEnums;
import cn.tannn.ops.nginx.entity.CloudAccessKey;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * https://shredzone.org/maven/acme4j/ca/index.html
 * https://shredzone.org/maven/acme4j/example.html
 * https://api.aliyun.com/api-tools/demo/Alidns/87dd2c5a-bb87-4269-8bb1-6e021be52123
 */
public class SimplifiedAcmeClient {
    private static final Logger LOG = LoggerFactory.getLogger(SimplifiedAcmeClient.class);

    /**
     * Invokes this example.
     */
    public static void main(String... args) {

        LOG.info("Starting up...");
        String domian = "tannn.cn";
        // 阿里云
//        try {
//            String accessKeyId = System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID");
//            String accessKeySecret = System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET");
//            CloudAccessKey cloudAccessKey = new CloudAccessKey();
//            cloudAccessKey.setAccessId(accessKeyId);
//            cloudAccessKey.setAccessSecret(accessKeySecret);
//            cloudAccessKey.setAccount("test.onaliyun.com");
//            cloudAccessKey.setCloud(CloudEnums.ALI);
//            AcmeUtil.run(domian,cloudAccessKey);
//        } catch (Exception ex) {
//            LOG.error("Failed to get a certificate for domains {}", domian, ex);
//        }

        // 华为云
        domian = "xx.top";
        try {
            String accessKeyId = System.getenv("HUAWEI_CLOUD_ACCESS_KEY_ID");
            String accessKeySecret = System.getenv("HUAWEI_CLOUD_ACCESS_KEY_SECRET");
            CloudAccessKey cloudAccessKey = new CloudAccessKey();
            cloudAccessKey.setAccessId(accessKeyId);
            cloudAccessKey.setAccessSecret(accessKeySecret);
            cloudAccessKey.setAccount("http_ssl");
            cloudAccessKey.setCloud(CloudEnums.HUAWEI);
            AcmeUtil.run(domian,cloudAccessKey);
        } catch (Exception ex) {
            LOG.error("Failed to get a certificate for domains {}",domian, ex);
        }
    }

}
